<template>
		<ul>
			<li class="view-childen-list"
					v-for="item in recommendList"
					:key="item.recommenderUuid"
					@click="chooseRecommend(item)">{{item.userName}}</li>
		</ul>
</template>
<script>
	import { Service } from '../../js/base'
	export default{
		props: {
			premisesId: {
				type: String | Number,
				default: '',
			}
		},
		data(){
			return {
				recommendList:[],
				defaultList: [
					{
						userName: "请选择",
						recommenderUuid: null,
						recommenderId: null
					}
				]
			}
		},
		mounted: function() {
	     this.init();
		},
		methods:{
			init () {
				this.getRecommendList(this.premisesId)
			},
			getRecommendList(id) {
				const _this = this
				if(!id) return
				const activate = '1' //1 启用， 0禁用
				return Service.Recommend.getRecommendList(id, this).then(list => {
					list = list.filter(item => item.status === activate);
					if(list && list.length > 0){
						_this.recommendList = [..._this.defaultList, ...list]
						this.chooseRecommend(_this.recommendList);
					}
					return list;
				})
			},
			chooseRecommend(info){
				this.$emit("choose", info)
			}
		},
		watch: {
			premisesId(val) {
				this.getRecommendList(val)
			}
		}
	}
</script>
